﻿using System.Globalization;
using System;
using System.Windows.Data;
using System.Windows.Media;

namespace Xcj.Mes.WholeLine.ZH.HG.Shell.Converter
{
    public class OutFeedResultForegroundConverter : IMultiValueConverter
    {
        public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
        {
            if (((values?.Length ?? 0) < 8)
                || (values[0] == null) || (values[1] == null)
                || (values[2] == null) || (values[3] == null)
                || (values[4] == null) || (values[5] == null)
                || (values[6] == null) || (values[7] == null))
                return Brushes.Red;

            try
            {
                int NotAgedResult      = int.Parse(values[0].ToString() ?? "0");
                int LC1Result          = int.Parse(values[1].ToString() ?? "0");
                int LC2Result          = int.Parse(values[2].ToString() ?? "0");
                int CapacityResult     = int.Parse(values[3].ToString() ?? "0");
                int LossResult         = int.Parse(values[4].ToString() ?? "0");
                int EsrResult          = int.Parse(values[5].ToString() ?? "0");
                int ConvexBottomResult = int.Parse(values[6].ToString() ?? "0");
                int ImplosionResult    = int.Parse(values[7].ToString() ?? "0");

                /*
                 * 开短路状态数据 00 无料 20 良品 11 开短路不良 12 重测 13 超上限(短路) 14 超下限(开路) 15 未触发或过流
                 * 未老化状态数据 00 无料 20 良品 11 未老化不良 12 重测 13 超上限 14 超下限 15 未触发或过流
                 * LC1状态数据    00 无料 20 良品 11 漏电不良   12 重测 13 超上限 14 超下限
                 * LC2状态数据    00 无料 20 良品 11 漏电不良   12 重测 13 超上限 14 超下限
                 * CX状态数据     00 无料 20 良品 11 损耗不良   12 重测 13 超上限 14 超下限 
                 * Esr状态数据    00 无料 20 良品 11 Esr不良    12 重测 13 超上限 14 超下限 
                 */

                if ((NotAgedResult == 20)
                    && (LC1Result == 20)
                    && (LC2Result == 20)
                    && (CapacityResult == 20)
                    && (LossResult == 20)
                    && (EsrResult == 20)
                    && ((ConvexBottomResult == 20) || (ConvexBottomResult == 0))
                    && ((ImplosionResult == 20) || (ImplosionResult == 0)))
                    return Brushes.Black;
                else
                {
                    if ((ConvexBottomResult != 20) && (ConvexBottomResult != 0))
                        return Brushes.Red;
                    else if ((ImplosionResult != 20) && (ImplosionResult != 0))
                        return Brushes.Red;
                    else if ((NotAgedResult == 11) || (NotAgedResult == 12) || (NotAgedResult == 13)  ||
                        (CapacityResult == 11) || (CapacityResult == 12) || (CapacityResult == 13)    ||
                        (LossResult == 11) || (LossResult == 12) || (LossResult == 13)                ||
                        (EsrResult == 11) || (EsrResult == 12) || (EsrResult == 13)                   ||                
                        (LC1Result == 11) || (LC1Result == 12) || (LC1Result == 13)                   ||
                        (LC2Result == 11) || (LC2Result == 12) || (LC2Result == 13))
                        return Brushes.Red;
                    else if ((NotAgedResult == 12)   ||
                             (CapacityResult == 12)  ||
                             (LossResult == 12)      ||
                             (EsrResult == 12)       ||
                             (LC1Result == 12)       ||
                             (LC2Result == 12))
                        return Brushes.DarkGray;
                    else
                        return Brushes.Black;
                }
            }
            catch { }

            return Brushes.Black;
        }

        public object[] ConvertBack(object value, Type[] targetTypes, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
}